package com.cityfood.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cityfood.mapper.CfUserAddressMapper;
import com.cityfood.pojo.CfUserAddress;
import com.cityfood.pojo.CfUserAddressExample;
import com.cityfood.pojo.CfUserAddressExample.Criteria;
import com.cityfood.service.AddressService;

@Service
public class AddressServiceImpl implements AddressService {
	
	@Autowired
	private CfUserAddressMapper addressMapper;

	@Override
	public List<CfUserAddress> getAddressByUserId(Integer userId) {
		CfUserAddressExample example=new CfUserAddressExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(userId);
		List<CfUserAddress> list = addressMapper.selectByExample(example);
		if (list.size()>0) {
			return list;
		}
		return null;
	}

	@Override
	public int insertAddress(CfUserAddress address) {
		int i = addressMapper.insertSelective(address);
		return i;
	}

	@Override
	public int updayeAddress(CfUserAddress address) {
		int i = addressMapper.updateByPrimaryKeySelective(address);
		return i;
	}

	@Override
	public int deleteAddress(Integer addressId) {
		int i = addressMapper.deleteByPrimaryKey(addressId);
		return i;
	}

}
